<?php
namespace app\manage\logic;

use app\manage\logic\BaseLogic;
use think\Db;
// 入口逻辑层
class Api extends BaseLogic
{
    protected $name = 'api';
    // 获取统计数据
    public function getCountData ()
    {
        return $this->db()->field('job_schedule, count(id) AS sum')
            ->where('status', 1)
            ->group('job_schedule')
            ->order('job_schedule')
            ->select();
    }

    // 根据传入的api_cate_id,获取相应的接口数据
    public function getCateApis ($data)
    {
        $list = Db::view('api', '*')
                ->view('api_cate', 'ver', 'api.api_cate_id=api_cate.id')
                ->where(['api.status' => 1, 'api.api_cate_id' => $data['api_cate_id']])
                ->order('api.job_schedule DESC, api.order ASC')
                ->select();
        return $list;
    }
    // 增加一个接口
    public function addApi ($data)
    {
        return $this->model('app\manage\model\Api')->save($data);
    }
    // 删除一个接口
    public function removeApi ($data)
    {
        $api['id'] = $data['id'];
        $api['status'] = 0;
        return $this->model('app\manage\model\Api')->update($api);
    }
}
